package com.atguigu.consumer;

import com.alibaba.fastjson.JSON;
import com.atguigu.constant.MqConst;
import com.atguigu.entity.OrderInfo;
import com.atguigu.entity.PaymentInfo;
import com.atguigu.enums.PaymentStatus;
import com.atguigu.enums.ProcessStatus;
import com.atguigu.feign.PaymentFeignClient;

import com.atguigu.service.PaymentInfoService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.util.Map;


/**
 * @author ：Hachimen
 * @date ：Created in 2021/9/8 18:49
 * @description：支付订单MQ消费者类
 * @modified By：
 * @version:
 */
@Component
public class PaymentConsumer {
    @Autowired
    private PaymentInfoService paymentInfoService;

    //关闭支付订单监视器
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MqConst.CLOSE_PAYMENT_QUEUE,durable = "false"),
            exchange = @Exchange(value = MqConst.CLOSE_PAYMENT_EXCHANGE,durable = "false"),
            key = {MqConst.CLOSE_PAYMENT_ROUTE_KEY}))
    public void closePayment(Long orderId, Message message, Channel channel) throws IOException {
        if (orderId!=null){
            //调用关闭支付信息的方法
            paymentInfoService.closePaymentInfo(orderId);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        }
    }
}
